package com.angis.fx.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;

public class RadioAdapter extends BaseAdapter {

	private List<String> mDataList;
	private LayoutInflater mLayoutInflater;

	public RadioAdapter(Activity pParamActivity) {
		mLayoutInflater = LayoutInflater.from(pParamActivity);
		mDataList = new ArrayList<String>();
	}

	@Override
	public int getCount() {
		return mDataList.size();
	}

	@Override
	public Object getItem(int position) {
		View lView = getView(position, null, null);
		ViewHolder lHodler = (ViewHolder)lView.getTag();
		return lHodler;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder lHolder = null;
		if (convertView == null) {
			lHolder = new ViewHolder();
			convertView = mLayoutInflater.inflate(com.angis.fx.activity.R.layout.radio_dialog_list_item, null);
			lHolder.mName = (TextView) convertView.findViewById(com.angis.fx.activity.R.id.radio_dialog_item_name);
			lHolder.mCkTextView = (CheckedTextView) convertView.findViewById(com.angis.fx.activity.R.id.radio_dialog_item_ctv);
		}else {
			lHolder = (ViewHolder) convertView.getTag();
		}
		String lData = mDataList.get(position).split("#")[0];
		lHolder.mName.setText(lData);
		convertView.setTag(lHolder);
		return convertView;
	}

	class ViewHolder {
		
		private TextView mName;
		private CheckedTextView mCkTextView;

		public TextView getName() {
			return mName;
		}

		public void setName(TextView pName) {
			this.mName = pName;
		}

		public CheckedTextView getCkTextView() {
			return mCkTextView;
		}

		public void setCkTextView(CheckedTextView mCkTextView) {
			this.mCkTextView = mCkTextView;
		}
		
	}
	
	public void setData(List<String> pDataList) {
		this.mDataList.clear();
		this.mDataList = pDataList;
	}

}
